﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BuildSDFDatabase;
using TextPioneer.ResearchDataProvider;
using TextPioneer;

namespace DataProviderTest
{
	class Program
	{
		static void Main(string[] args)
		{
			string dbPath = Path.Combine(args[0], "research.sdf");
			ProposalPaperDataProvider dataProvider = new ProposalPaperDataProvider();
			dataProvider.Initialize(dbPath);
			int before = Environment.TickCount;
			var start = dataProvider.StartTime;
			Debug.WriteLine("Read StartTime {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var end = dataProvider.EndTime;
			Debug.WriteLine("Read EndTime {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var corpora = dataProvider.GetCorpora();
			Debug.WriteLine("Read Corpora {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var rootBundles0 = dataProvider.GetTopLevelTopics(corpora[0]);
			Debug.WriteLine("Read RootBundles {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var childBundles0 = rootBundles0[0].GetChildren();
			Debug.WriteLine("Read RootChildren {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			TopicNode[] topics0 = (childBundles0[0] as ProposalPaperTopicBundle).GetChildren();
			Debug.WriteLine("Read BundleChildren {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var rootBundles1 = dataProvider.GetTopLevelTopics(corpora[1]);
			Debug.WriteLine("Read RootBundles {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var childBundles1 = rootBundles1[0].GetChildren();
			Debug.WriteLine("Read RootChildren {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			TopicNode[] topics1 = (childBundles1[0] as ProposalPaperTopicBundle).GetChildren();
			Debug.WriteLine("Read BundleChildren {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var trends = dataProvider.GetLeadingTrends(topics0[0] as Topic, topics1[0] as Topic);
			var pairs = dataProvider.GetSimilarityPairs(topics0[0] as Topic, topics1[0] as Topic);
			Debug.WriteLine("Read LeadingTrend and DocumentMatrix {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			var words = dataProvider.GetKeywords(topics0[0], KeywordRanking.TF, 20);
			var words1 = dataProvider.GetKeywords(topics1[0], KeywordRanking.TF, 20);
			var tfidfWords = dataProvider.GetKeywords(topics0[0], KeywordRanking.TFIDF, 20);
			var tfidfWords1 = dataProvider.GetKeywords(topics1[0], KeywordRanking.TFIDF, 20);
			Debug.WriteLine("Read Keywords {0}", Environment.TickCount - before);
			before = Environment.TickCount;
		
			var docs = dataProvider.GetEntities("Document", topics0[0] as Topic, new DateTime(2000, 1, 1));
			var programs = dataProvider.GetEntities("Program", topics0[0] as Topic, new DateTime(2000, 1, 1));
			var authors = dataProvider.GetEntities("Author", topics0[0] as Topic, new DateTime(2000, 1, 1));
			var docs1 = dataProvider.GetEntities("Document", topics1[0] as Topic, new DateTime(2000, 1, 1));
			var programs1 = dataProvider.GetEntities("Program", topics1[0] as Topic, new DateTime(2000, 1, 1));
			var authors1 = dataProvider.GetEntities("Author", topics1[0] as Topic, new DateTime(2000, 1, 1));
			Debug.WriteLine("Read Entities {0}", Environment.TickCount - before);
			before = Environment.TickCount;

			dataProvider.Dispose();
			//int[] documentIds;
			//foreach (var topic in topics)
			//{
			//	documentIds = (topic as ProposalPaperTopic).GetDocumentIds(
			//	topics[0].StartTime, topics[0].EndTime);
			//}
			//Debug.WriteLine("Read Documents {0}", Environment.TickCount - before);
			//before = Environment.TickCount;
		}
	}
}
